//
//  HJDRootTool.m
//  JYHospital
//
//  Created by 胡金东 on 16/3/31.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDRootTool.h"
#import "HJDTabBarController.h"
#import "HJDNewFeatureController.h"
#import "HJDPesonalCenterViewController.h"
#import "HJDTabBarController.h"
#import "RESideMenu.h"


//版本号
#define HJDVersionKey @"version"

@interface HJDRootTool ()<RESideMenuDelegate>

@end


@implementation HJDRootTool


+(void)chooseNewFeatureRootViewController:(UIWindow *)window
{
    HJDTabBarController *tabBar = [[HJDTabBarController alloc]init];
            HJDPesonalCenterViewController *personalVC = [[HJDPesonalCenterViewController alloc] init];
    
            RESideMenu *sideMenuViewController = [[RESideMenu alloc]initWithContentViewController: tabBar leftMenuViewController:personalVC  rightMenuViewController:nil];
    
            sideMenuViewController.backgroundImage = [UIImage imageNamed:@"bg"];
            sideMenuViewController.menuPreferredStatusBarStyle = 1; // UIStatusBarStyleLightContent
            sideMenuViewController.delegate = self;
            sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
            sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
            sideMenuViewController.contentViewShadowOpacity = 0.2;
            sideMenuViewController.contentViewShadowRadius = 12;
            sideMenuViewController.contentViewShadowEnabled = YES;
    


    //1.获取当前的版本号
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
    //2.获取上一次的版本号
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults]objectForKey:HJDVersionKey];
//    判断当前是否有新的版本，是否显示新特性
    if ([currentVersion isEqualToString:lastVersion] ) {
//        没有更新版本号，就不显示新特性，直接显示tabBar
//        创建tabBar
        
//        设置窗口的根控制器
        window.rootViewController = tabBar;
    }else{//有新的版本号，显示新特性，并保存版本号
//        新特性
        HJDNewFeatureController *NFColl = [[HJDNewFeatureController alloc]init];
       
        window.rootViewController = NFColl;

//        保存当前的版本，用偏好设置
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:HJDVersionKey];
    }
    
}






@end
